/*
 * Copyright 2012-2022 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.validation.beanvalidation;

import java.lang.annotation.Annotation;

import org.springframework.core.annotation.MergedAnnotations;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;

/**
 * 用于从方法验证中排除类型的过滤器。
 *
 * @author Andy Wilkinson
 * @since 2.4.0
 * @see FilteredMethodValidationPostProcessor
 */
public interface MethodValidationExcludeFilter {

	/**
	 * 评估是否将给定的 {@code type} 从方法验证中排除。
	 *
	 * @param type 要评估的类型
	 * @return {@code true} 表示从方法验证中排除该类型，否则返回 {@code false}
	 */
	boolean isExcluded(Class<?> type);

	/**
	 * 工厂方法，用于创建一个 {@link MethodValidationExcludeFilter}，
	 * 该过滤器通过使用 {@link SearchStrategy#INHERITED_ANNOTATIONS 继承注解搜索策略}
	 * 找到的注解来排除类。
	 *
	 * @param annotationType 要检查的注解
	 * @return {@link MethodValidationExcludeFilter} 实例
	 */
	static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType) {
		return byAnnotation(annotationType, SearchStrategy.INHERITED_ANNOTATIONS);
	}

	/**
	 * 工厂方法，用于创建一个 {@link MethodValidationExcludeFilter}，
	 * 该过滤器通过使用给定搜索策略找到的注解来排除类。
	 *
	 * @param annotationType 要检查的注解
	 * @param searchStrategy 注解搜索策略
	 * @return {@link MethodValidationExcludeFilter} 实例
	 */
	static MethodValidationExcludeFilter byAnnotation(Class<? extends Annotation> annotationType,
													  SearchStrategy searchStrategy) {
		return (type) -> MergedAnnotations.from(type, searchStrategy).isPresent(annotationType);
	}

}
